package jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * 字段别名
 */
public class JDBCDemo7 {
    public static void main(String[] args) {
        //查看1年级1班一共多少人?
        try (
                Connection conn = DBUtil1.getConnection();
        ) {
            Statement statement = conn.createStatement();
            String sql = "SELECT COUNT(*) count " +
                    "FROM class c " +
                    "JOIN student s ON c.id=s.class_id " +
                    "WHERE c.name='1年级1班'";
            ResultSet rs = statement.executeQuery(sql);
            if (rs.next()) {
                int count = rs.getInt("count");
                System.out.println("共:" + count + "人");
            }


        } catch (SQLException e) {
            e.printStackTrace();
        }

    }
}








